// Author: Mohamed Abdel Hakim
$(document).ready(function()
{
    $(window).resize(function()
    {
        if($("#nav").offset().left<0) {
            //$("#bt").html("View menu");
            $("#collabsoft").width("100%");
        }
        else {
            //$("#bt").html("Hide menu");
            $("#collabsoft").width(parseInt($(window).width())-parseInt($("#nav").width()));
        }
    });
    $("#collabsoft").find("a").live("click", function(event) { // function to handle click events of menu anchors

        var page = $(this).attr("href"); // getting the href of the anchor
        if($(this).attr("target") != ("_blank")) {
             event.preventDefault();
        $("#collabsoft").slideUp("500",function() {
            $("#collabsoft").load(page,function()
            {
                $(this).slideDown(500);
            });
        });
         }

    });
    $("#collabsoft").find("form").live("submit", function(event) {

      event.preventDefault();
       $.ajax({
            data: $(this).serialize(),
            type: $(this).attr('method'),
            url: $(this).attr('action'),
            success: function(response) {

                $("#collabsoft").slideUp(500, function() {
                    $("#collabsoft").html(response);
                    $("#collabsoft").slideDown(500);
                });
            }
        });


        return false;
    });

    $("#nav a").click(function(event) { // function to handle click events of menu anchors
        event.preventDefault();
        var page = $(this).attr("href"); // getting the href of the anchor
        $("#collabsoft").slideUp("500",function() {
            $("#collabsoft").load(page,function()
            {
                $(this).slideDown(500);
            });
        });
        return false;
    });
    $("#footer a").click(function(event) { //function to handle click events of footer anchors
        event.preventDefault();
        var page = $(this).attr("href");             // same scenario as before
        $('#collabsoft').slideUp("500",function() {
            $("#collabsoft").load(page,function()
            {
                $(this).slideDown(500);

            });
        });
        return false;
    });

    document.getElementById("collabsoft").onload=function()
    {
        if(parseInt($("#nav").css("right"))<20)
            $("#collabsoft").width($(window).width()*0.99);
        else
            $("#collabsoft").width($(window).width()-$("#nav").width()-200);
    }
});